home *** CD-ROM | disk | FTP | other *** search
- Path: news.rain.org!usenet
- From: "Guus Leeuw jr." <guusl@eiffel.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Deleting arrays of garbage collectables
- Date: Wed, 10 Jan 1996 13:19:15 -0800
- Organization: ISE Inc. http://www.eiffel.com
- Message-ID: <30F42D53.3B4D1687@eiffel.com>
- References: <4d0mbf$6on@news.ox.ac.uk>
- NNTP-Posting-Host: @outback.eiffel.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (X11; I; Linux 1.2.8 i586)
-
- Michael Brewer wrote:
- >
- > Probably a bad subject line, but here is what I mean:
- >
- > I am using a bunch of classes that can be shared by the mechanism:
- >
- > class Allo; // defined elsewhere
- >
- > Allo *hi = new Allo;
- > hi->ref(); // Using this object
- > //..... code
- > hi->unref(); // finished with it. If it hasn't been ref()'ed
- > // elsewhere, it will be deleted
- >
- > Now what if I want an array of these? There is no satisfactory default
- > constructor, so I need an array of pointers:
- >
- > Allo **arr = new Allo * [10];
- > for(int i = 0; i < 10; i++)
- > {
- > arr[i] = new Allo(3.221);
- > arr[i]->ref();
- > }
- > // ......... code
- > // ....
- > // finished, unref():
- > for(int i = 0; i < 10; i++)
- > arr[i]->unref();
- >
- > OK, so now the arr[i] memory has been dealt with, but what about the
- > array of pointers arr?? There is no way of telling whether they still
- > point to something, since some other object may still be sharing the
- > data.
- >
- > Is there a way to free up that memory?
-
- I think there is, it'll cost a bit of work though.
-
- I think you should write your own Array class (template (!)) which
- provides exactly the same mechanism. Form time to time you call a member
- function that checks whether there are still pointers that are ref'ed in
- the array. If not the object's memory will be freed, etc. etc.
- >
- > Thanks.
- >
- > Mike
-
- Hope this helps and regards,
- Guus Leeuw jr.
-